<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>菜单管理</title>
<%@ include file="/common/header/meta.jsp"%>
<%@ include file="/common/header/script.jsp"%>
<script type="text/javascript">
	var $tg;
	$(function() {
		$tg = $("#tg").treegrid({
			 url: base.contextPath+"/sysmgr/menu/treegrid.do",
			 title: '<span style="font-weight:normal;color:#666;">系统基础配置-->系统管理-->菜单管理</span>', 
			 idField: 'id', treeField: 'name', rownumbers: true, cascadeCheck: true,
	         remoteSort: false, fit: true,toolbar: '#toolbars', striped:true, singleSelect: false,
	         frozenColumns: [[
	             { field: 'ck', checkbox: true },
	             { field: 'id', title: 'ID', hidden: true }
	         ]],
	         columns: [[
             	{ field: 'name', title: '名称', width: 220, sortable: true },
	    		{ field: 'sort', title: '排序', width: 50, sortable: true, editor: "numberbox" },
			    { field: 'type', title: '菜单类型', width: 70, sortable: true, formatter:function(value,row){
			    	if(value == "R"){return "导航栏目";}else if(value == "F"){return "<font color='green'>导航菜单</font>";}else{return "<font color='red'>菜单操作</font>";}
			    }},
			    { field: 'href', title: '链接地址', width: 250, editor: "text", tooltip: true },
			    { field: 'isShow', title: '是否显示', width: 110, sortable: true, align: 'center', formatter:function(value,row){
			    	if(row.type != "O") {
				    	return "<div class='on_off' style='width:91px;margin:0 auto;'><input id='"+row.id+"' type='checkbox' "+(value==0?'checked':'')+" /></div>" ;
			    	}
			    }},
			    { field: 'permitCode', title: '权限代码', width: 90 },
			    { field: 'action_value', title: '操作', width: 90 },
			    { field: 'target', title: '打开目标', width: 65 },
			    { field: 'state', title: '展开', width: 55 },
			    { field: 'modifyDate', title: '最后修改时间', width: 140 },
			    { field: 'modifyName', title: '修改者', width: 80 },
			    { field: 'created', title: '创建时间', width: 140, sortable: true }
	         ]],
	         autoEditing: true,enableHeaderClickMenu: false,enableHeaderContextMenu: false,
	         onAfterEdit: function(data) {
				$.fn.treegrid.extensions.onAfterEdit.apply(this, arguments);
				$.post(base.contextPath+"/sysmgr/menu/doNotNeedAuth_sort.do", {"id":data.id, "sort":data.sort, "href":data.href}, function(result) {
					if (result.status) {
						$tg.treegrid('clearSelections');$tg.treegrid('clearChecked');
						alertify.success(result.msg);
					} else {
						alertify.warning(result.msg);
					}
				}, 'json');
	         },
	         onLoadSuccess: function() {
	        	$('.on_off :checkbox').iphoneStyle({
	     			onChange: function(elem, value){
	     				$.post(base.contextPath+"/sysmgr/menu/isShow_hide.do", {"id":$(elem).attr("id"), "isShow":(value==true?"0":"1")}, function(result) {
	     					if (result.status) {
	     						$tg.treegrid('clearSelections');$tg.treegrid('clearChecked');
	     						alertify.success(result.msg);
	     					} else {
	     						alertify.warning(result.msg);
	     					}
	     				}, 'json');
	     			}
	     		});
	         }
		}) ;
	});
	
	
	function form_edit(form) {
		var form_url = base.contextPath+"/sysmgr/menu/menu_form.do" ;
		if("E" == form) {
			var node = $tg.treegrid('getSelected');
			if (node) {
				form_url = base.contextPath+"/sysmgr/menu/menu_form.do?id="+node.id ;
			} else {
				alertify.warning("请选择一条记录！"); return ;
			}
		}
		var $d = $.easyui.showDialog({
			href: form_url, title: "表单", iniframe: false, topMost: true, width: 740 , height: 400,
	        enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
	        buttons : [ 
			  { text : '保存并继续', iconCls : 'icon-standard-disk', handler : function() { $.easyui.parent.submitForm($d, $tg, true) ; } },
	          { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $tg) ; } },
	          { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } }
	       	]
	    });
	}
	
	function del() {
		var node = $tg.treegrid('getSelected');
		if(node){
			$.messager.confirm("您确定要进行该操作？", function (c) { 
				if(c) {
					$.easyui.loading({ msg: "数据删除中，请稍等..." });
					$.post(base.contextPath+"/sysmgr/menu/delete.do", {id:node.id}, function(result) {
						if (result.status) {
							$tg.treegrid('reload') ;
							alertify.success(result.msg);
							$.easyui.loading({ msg: "正在加载...", locale: "#westCenterLayout", topMost: true });
							$.util.exec(function () { 
								$.easyui.parent.window.mainpage.refreshNavTab(); 
								$.easyui.loaded(true);
								$.easyui.loaded();
							},2000);
							
						} else {
							$.easyui.loaded();alertify.error(result.msg);
						}
					}, 'json').error(function(){$.easyui.loaded();});
				} else {$.easyui.loaded("#westCenterLayout", true);}
			});
		} else {
			alertify.warning("请选择一条记录！");
		}
	}

</script>
</head>

<body>
	<div id="tg">
		<div id="toolbars">
            <a onClick="form_edit('A');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_add'">添加</a>
            <a onClick="form_edit('E');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_edit'">编辑</a>
            <a onClick="del();" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_remove'">删除</a>
            <a onclick="$tg.treegrid('reload');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_reload'">刷新</a>
        </div>
	</div>

</body>
</html>